package controllers

import (
	"github.com/astaxie/beego"
	"shopping/models"
	"shopping/helper"
	"github.com/astaxie/beego/orm"
)

var (
	item models.Item
    itemnum models.Itemnum
    order models.Order
)

// CMS API
type ShowController struct {
	beego.Controller
}

// @Title getStaticBlock
// @Description get all the staticblock by key
// @Param   key     path    string  true        "The email for login"
// @Success 200 {object} models.ZDTCustomer.Customer
// @Failure 400 Invalid email supplied
// @Failure 404 User not found
// @router /staticblock/:key [get]
func (this *ShowController) Showcart() {
	//uid := helper.Sti(this.GetString("u"))
	uid := int(3)
	var maps []orm.Params = models.Queryitems(uid)
	beego.Debug("aaa", maps)
	this.Data["list"] = maps
	this.TplName = "mycart.html"
}

func (this *ShowController) Additem() {
	pid := helper.Sti(this.GetString("p"))
	beego.Debug("pid", pid)
	num := helper.Sti(this.GetString("n"))
	beego.Debug("num", num)

	var item models.Item

	var s = item.Additem(pid, int(3), num)

	resultjson := map[string]string{"status": s,"error":"NO"}
	this.Data["json"] = &resultjson
	this.ServeJSON()
}

func (this *ShowController) Addmin() {
	pid := helper.Sti(this.GetString("p"))
	num := helper.Sti(this.GetString("n"))
	beego.Debug("pid", pid)
	beego.Debug("num", num)

	//beego.Debug("pid",pid)
	var s = itemnum.Addmin(pid, num)
	resultjson := map[string]string{"status": s}
	this.Data["json"] = &resultjson
	this.ServeJSON()
}

// @Title Get Product list
// @Description Get Product list by some info
// @Success 200 {object} models.ZDTProduct.ProductList
// @Param   category_id     query   int false       "category id"
// @Param   brand_id    query   int false       "brand id"
// @Param   query   query   string  false       "query of search"
// @Param   segment query   string  false       "segment"
// @Param   sort    query   string  false       "sort option"
// @Param   dir     query   string  false       "direction asc or desc"
// @Param   offset  query   int     false       "offset"
// @Param   limit   query   int     false       "count limit"
// @Param   price           query   float       false       "price"
// @Param   special_price   query   bool        false       "whether this is special price"
// @Param   size            query   string      false       "size filter"
// @Param   color           query   string      false       "color filter"
// @Param   format          query   bool        false       "choose return format"
// @Failure 400 no enough input
// @Failure 500 get products common error
// @router /products [get]
func (this *ShowController) Deleteitem() {
	pid := helper.Sti(this.GetString("p"))

	//beego.Debug("pid",pid)
	var s = item.Deleteitem(pid)
	resultjson := map[string]string{"status": s}
	this.Data["json"] = &resultjson
	this.ServeJSON()
}

func (this *ShowController) Getorder() {
	beego.Debug("aaa")
	ids := this.GetStrings("ids")
	totalp := this.GetString("totp")
	//beego.Debug("idsssss",ids)
	//beego.Debug("totalp",totalp)

	//beego.Debug("pid",pid)
	//var s= item.Deleteitem(pid)
	var uid = int(3)
	var remarks = "订单备注"
	var s = order.Addorder(ids, uid, remarks, helper.Stf64(totalp))
	resultjson := map[string]string{"status": s}
	this.Data["json"] = &resultjson
	this.ServeJSON()
}

func (this *ShowController) Query()  {
	uid := int(3)
	var maps []orm.Params = models.Queryitems(uid)
	beego.Debug("aaa", maps)
	this.Data["json"] = maps
	this.ServeJSON()
}